#include "stdafx.h"
#include "TestingFunction.h"

double TestingFunction::getF(double x)
{
	double f;
	switch (type)
	{
	case FunctionTypeTesting: 
		if (x < 0) f = x*x*x + 3*x*x;
		else f = (-1)*x*x*x + 3*x*x;
		break;
	case FunctionTypeMyFunction: 
		f = sin(x + 1) / x;
		break;
	case FunctionTypeMyFunctionOscil10:
		f = sin(x + 1) / x + cos(10 * x);
		break;
	case FunctionTypeMyFunctionOscil100:
		f = sin(x + 1) / x + cos(100 * x);
		break;
	}
	return f;
}

double TestingFunction::getDiffOne( double x )
{
	double diff;
	switch (type)
	{
	case FunctionTypeTesting: 
		if (x < 0) diff = 3*x*x + 6*x;
		else diff = (-3)*x*x + 6*x;
		break;
	case FunctionTypeMyFunction: 
		diff = (x * cos(x + 1) - sin(x + 1)) / (x*x);
		break;
	case FunctionTypeMyFunctionOscil10:
		diff = cos(x + 1) / x - 10 * sin(10 * x) - sin(x + 1) / (x*x);
		break;
	case FunctionTypeMyFunctionOscil100:
		diff = cos(x + 1) / x - 100 * sin(100 * x) - sin(x + 1) / (x*x);
		break;
	}
	return diff;
}

double TestingFunction::getDiffTwo( double x )
{
	double diffTwo;
	switch (type)
	{
	case FunctionTypeTesting: 
		if (x < 0) diffTwo = 6*x + 6;
		else diffTwo = (-6)*x + 6;
		break;
	case FunctionTypeMyFunction: 
		diffTwo = ((2 - x*x) * sin(x + 1) - 2*x*cos(x+1)) / (x*x*x);
		break;
	case FunctionTypeMyFunctionOscil10:
		diffTwo = ((2 - x*x) * sin(x + 1) - 2*x*cos(x+1)) / (x*x*x) - 100*cos(10*x);
		break;
	case FunctionTypeMyFunctionOscil100:
		diffTwo = ((2 - x*x) * sin(x + 1) - 2*x*cos(x+1)) / (x*x*x) - 10000*cos(100*x);
		break;
	}
	return diffTwo;
}


